package com.ayf.payment.game.api.service.sign;

import com.ayf.payment.game.api.dto.platform.PaymentChannelDTO;
import com.ayf.payment.game.api.dto.sign.*;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.service.platform.PaymentChannelService;
import com.ayf.payment.game.api.service.sign.handler.MerchantTwoAybSignHandlerImpl;
import com.ayf.payment.game.api.service.sign.handler.MerchantTwoAyfSignHandlerImpl;
import com.ayf.payment.game.api.service.sign.handler.MerchantTwoSignHandler;
import com.ayf.payment.game.api.service.sign.handler.MerchantTwoWXYFTSignHandlerImpl;
import com.ayf.payment.game.api.service.sign.handler.MerchantTwoZFYSignHandlerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: zh-liang
 * @Date: 2022-03-11 16:14
 */
@Component
public class MerchantTwoSignServiceImpl implements MerchantTwoSignService {

    @Autowired
    private PaymentChannelService paymentChannelService;
    @Autowired
    private MerchantTwoAybSignHandlerImpl merchantTwoAybSignHandler;
    @Autowired
    private MerchantTwoAyfSignHandlerImpl merchantTwoAyfSignHandler;
    @Autowired
    private MerchantTwoWXYFTSignHandlerImpl merchantTwoWXYFTSignHandler;
    @Autowired
    private MerchantTwoZFYSignHandlerImpl merchantTwoZFYSignHandler;

    private MerchantTwoSignHandler getChannelCode(String code) {
        if ("AYF_SPLIT_PAY".equals(code)) {
            return merchantTwoAyfSignHandler;
        }else if("WXYFT".equals(code)){
            return merchantTwoWXYFTSignHandler;
        } else if ("AYB_PAY".equals(code)){
            return merchantTwoAybSignHandler;
        } else if ("ZFYFZ".equals(code)) {
            return merchantTwoZFYSignHandler;
        }
        throw new ParameterException("分账路由不存在");
    }

    private PaymentChannelDTO getChannel(String code) {
        return paymentChannelService.getPaymentChannelByCode(code);
    }

    @Override
    public MerchantTwoApplyResDTO merchantTwoApply(MerchantTwoApplyReqDTO reqDTO) {
        PaymentChannelDTO channel = getChannel(reqDTO.getChannelCode());
        return getChannelCode(channel.getCode()).merchantTwoApply(reqDTO, channel);
    }

    @Override
    public boolean merchantTwoApplyAsyncExec(MerchantTwoApplyAsyncReqDTO reqDTO) {
        PaymentChannelDTO channel = getChannel(reqDTO.getChannelCode());
        return getChannelCode(channel.getCode()).merchantTwoApplyAsyncExec(reqDTO, channel);
    }

    @Override
    public MerchantTwoSelectResDTO merchantTwoSelect(MerchantTwoSelectReqDTO reqDTO) {
        PaymentChannelDTO channel = getChannel(reqDTO.getChannelCode());
        return getChannelCode(channel.getCode()).merchantTwoSelect(reqDTO, channel);
    }

    @Override
    public MerchantTwoUpdateResDTO merchantTwoUpdate(MerchantTwoUpdateReqDTO reqDTO) {
        PaymentChannelDTO channel = getChannel(reqDTO.getChannelCode());
        return getChannelCode(channel.getCode()).merchantTwoUpdate(reqDTO, channel);
    }

    @Override
    public MerchantTwoUpdateSuperResDTO merchantTwoUpdateSuper(MerchantTwoUpdateSuperReqDTO reqDTO) {
        PaymentChannelDTO channel = getChannel(reqDTO.getChannelCode());
        return getChannelCode(channel.getCode()).merchantTwoUpdateSuper(reqDTO, channel);
    }
}
